package com.example.common.consumer.controller;

import com.example.common.consumer.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;

/**
 * @author wangjinlong
 * @date 2022/2/11 16:18
 */
@RestController
@RequestMapping("api/common/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    ApplicationContext applicationContext;

    @Autowired
    private ConsumerService consumerService;

    @Value("${api.common.consumer.config:0}")
    private Integer config;

    @GetMapping("get")
    public String get(){
        String s = consumerService.get();
        return "hello I'm consumer config = " + config + " | " + s;
    }

    @PostConstruct
    public void test(){
        String[] names = applicationContext.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }
}
